var base = $('base').attr('ul'); 
$(document).ready(function()
        {
            (function($){
                $.fn.resize=function(callback){
                    $(this).each(function(){
                        var resizeDom = this;
                        resizeDom.callback = callback;

                        if(this == window){
                            window.onresize=function(){
                                resizeDom.callback();
                            };
                        }else{
                            $(this).divResize(callback);
                        }
                    });
                };

                $.fn.divResize=function(callback){
                    var cycleTime = 250; // 定义监控大小变化的时间
                    if(callback==undefined||callback==null){
                        return;
                    }
                    if(!(typeof callback == "function")){
                        return;
                    }

                    $(this).each(function(){
                        var resizeDom = this;
                        resizeDom.data = {};
                        resizeDom.data.width = $(resizeDom).css("width"); // 存放当前宽度
                        resizeDom.data.height = $(resizeDom).css("height"); // 存放当前高度
                        resizeDom.callback = callback;
                        var resizeMonitor = function(){
                            if($(resizeDom).css("width")!=resizeDom.data.width||$(resizeDom).css("height")!=resizeDom.data.height){
                                resizeDom.data.width = $(resizeDom).css("width");
                                resizeDom.data.height = $(resizeDom).css("height");
                                resizeDom.callback();
                            }
                            var callFunc = arguments.callee; // 获取本身函数
                            setTimeout(function(){callFunc();}, cycleTime);
                        };
                        resizeMonitor();
                    });
                };

            }(jQuery));

               function pg_h(){
                   if($(window).width()<991){
                       $(".page-sidebar").addClass('list_nav');
                       $(".list_nav").resize(function(){
                           var body_h = $(document.body).height();
                           var navbar_h = $('.navbar').height();
                           var page_sidebar_h = $('.list_nav').outerHeight();
                           var page_sidebar_hh =  body_h - navbar_h  - page_sidebar_h;
                           console.log(body_h+'--'+'--'+page_sidebar_h+'--'+navbar_h+'--'+page_sidebar_hh);
                           $('.page-content').css({'min-height':page_sidebar_hh,'overflow':'auto'});
                       });
                   }else{
                       $(".page-sidebar").removeClass('list_nav');
                   }
               }
            pg_h();
            $(window).resize(function(){
                pg_h();
            });

            $('#clickmewow').click(function()
            {
                $('#radio1003').attr('checked', 'checked');
            });

            //首页的iframe
             $('iframe').attr('src',base+'/page/statistic/');
            //点击切换iframe并更换tab的样式
            $('.sub-menu .nav-item').click(function(){
                $(this).parent('.sub-menu').parent('.nav-item').addClass('active').siblings().removeClass('active');
                $(this).addClass('active').siblings().removeClass('active');

                if($(window).width() < 992){
                    $('.menu-toggler').click();
                }
            });

            //点击tab栏首页
            $('.start').click(function(){
                $('iframe').attr('src',base+'/page/statistic/'); //跳转到首页;
                $(this).addClass('active').siblings().removeClass('active open');//给首页tab加上active,移除兄弟节点的active
                $(this).siblings().children('.sub-menu').css('display','none').children().removeClass('active');
            });
            
            //点击修改密码
            $('.change-password').click(function(){
                    layer.open({
                        type : 2,
                        content : base+ '/sys/user/changePwd',
                        title : '修改密码',
                        btn : ['确认','关闭'],
                        area: ['600px','400px'],
                        yes:function (index, layero) {
                            $(layer.getChildFrame('.btn-confirm', index)).trigger('click');
                            var oldPwd= $(layer.getChildFrame('.oldPwd', index)).val();
                           var newPwd=    $(layer.getChildFrame('.newPwd', index)).val();
                           var confirmPwd=   $(layer.getChildFrame('.confirmPwd', index)).val();
                            $.ajax({
                                url : base +'/sys/user/updatePwd',
                                type : 'POST',
                                dataType : 'JSON',
                                data : {'oldPwd':oldPwd,'newPwd':newPwd,'confirmPwd':confirmPwd},
                                success : function (result) {
                                	console.log(result.code)
                                
                                	if(result.code === 500){
                                		layer.msg(result.msg)
                                		console.log(result.msg)
                                	}else if(result.code === 0){
                                		layer.msg('修改密码成功')
                                    	layer.close(index)
                                	}
                                }
                            });

                        },
                    });
                });
            
    
            
        })